/**
 *
 */
package com.angel.architecture.services.locator;

import org.apache.log4j.Logger;

import com.angel.architecture.services.locator.strategies.ServiceLocatorStrategy;
import com.angel.architecture.services.locator.strategies.impl.AngelServiceLocatorStrategy;

/**
 * @author William
 *
 */
public class ServiceLocator {

	private static Logger LOGGER = Logger.getLogger(ServiceLocator.class);
	private static ServiceLocatorStrategy locatorStrategy = new AngelServiceLocatorStrategy();

	public static void setLocatorStrateg(ServiceLocatorStrategy strategy) {
		locatorStrategy = strategy;
	}

	public static <T> T locate(Class<T> serviceClass) {
		return locate(serviceClass, false);
	}

	public static <T> T locate(Class<T> serviceClass, boolean searchAmongNotFinishedOnes) {
		LOGGER.debug("Locating service class [" + serviceClass.getCanonicalName() + "].");
		return locatorStrategy.locate(serviceClass, searchAmongNotFinishedOnes);
	}

	public static <T> T locate(String serviceName) {
		LOGGER.debug("Locating service name [" + serviceName + "].");
		return locatorStrategy.locate(serviceName, false);
	}

	public static <T> T locate(String serviceName, boolean searchAmongNotFinishedOnes) {
		LOGGER.debug("Locating service name [" + serviceName + "].");
		return locatorStrategy.locate(serviceName, searchAmongNotFinishedOnes);
	}
}
